(function ($) {
	var loginID = '',today = '',afterMonthDay = ''
	var classArr = []
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		today = getCurrentDeviceDay()
		afterMonthDay = getDayAfterMonth(today,1)
		var perInfo = app.getState()
		loginID = perInfo.loginID
		var slider = document.getElementById('slider');
		slider.addEventListener('slide', function(event) {
			var index = event.detail.slideNumber;
			refreshMainPage(index)
			$('#sliderIndicator .mui-indicator[data-index="'+index+'"]')[0].classList.add('mui-active');
		});
		var indicators = document.querySelectorAll('#sliderIndicator .mui-indicator');
		for (var i = 0; i < indicators.length;i++) {
			indicators[i].addEventListener('tap',function(){
				var oldActive = $('#sliderIndicator .mui-indicator.mui-active')[0];
				if (oldActive) {
					if (oldActive == this) {
						return
					}
					oldActive.classList.remove('mui-active')
				}
				var newIndex = parseInt(this.getAttribute('data-index'))
				refreshMainPage(newIndex);
				this.classList.add('mui-active')
				mui('#slider').slider().gotoItem(newIndex,100)
			});
		}
		mui('#trainWrapper').on('tap','.openWindow',toTrainOrOrder);
		mui('#examineWrapper').on('tap','.openWindow',toTrainOrOrder);
		//APPMenu 菜单显示与否
		var APPMenu = app.getState().APPMenu
		if (!APPMenu) {
			return
		}
		mui('.noPermission').each(function (domIndex,dom) {
			var code = dom.getAttribute('data-menu')
			if (code && code!="" && APPMenu[code]) {
				dom.classList.remove('noPermission')
			}
		})
		getTrainData()
		getExamData()
	}
	
	///刷新培训和考核主界面数据
	function refreshMainPage(index){
		if (index == 0) {
			getTrainData()
		}else{
			getExamData()
		}
		
	}
	
	function getActiveSegmentType(){
		var type = 'class'
		var activeDom = $('#sliderIndicator .mui-indicator.mui-active')[0];
		if (activeDom) {
			var index = activeDom.getAttribute('data-index');
			if (index == 1) {
				type = 'examine'
			}
		}
		return type
	}
	window.addEventListener('listenner', function(e) {
		if (e.detail.dblTap) {
			mui('#trainWrapper').scroll().scrollTo(0, 0, 100);
			mui('#examineWrapper').scroll().scrollTo(0, 0, 100);
		}
	});
	
	function toExamOrOrder(){
		var activeType = getActiveSegmentType();
		var pageName = this.getAttribute('data-page')
		var title = ''
		var data = {}
		if (pageName == 'toOrder') {
			data = {"rw":"13","AutoScoreType":"Y","CheckWork":"R","ChildVideoInfo":"4@%Library.RelationshipObject","ClassDraw":"Y","ClassDuration":"10","ClassPaperType":"I","ClassPass":"50","ClassQuesRange":"B」」3」30」90」1,3","ClassQuesRangeI":"3||5」30「3||6」30「3||7」30","ClassResit":"Y","ClassResitNum":"3","ClassScore":"90","ClassType":"54||1","CoursesType":"N","CreatDate":"2023-12-04","CreatTime":"36377","Creator":"469","DrillCharge":"469","DrillCredit":"5","DrillCreditType":"A","DrillPerNum":"","DrillScore":"","EndDate":"2024-01-31","Examinee":"NURSELEVEL","ExamineeList":"19||2,19||3,19||4","ExamineeWard":"","Examiner":"469","HomeworkDateTime":"2024-01-31 09:59","HomeworkDesc":"课后作业噢噢噢","HomeworkPass":"60","HomeworkScore":"100","QRCode":"S","ReleaseDesc":"臧阳爽的24年线下培训","ReleaseDrillType":"49||6","ReleaseLevel":"H","ReleaseWay":"D","ResultDraw":"Y","ResultDuration":"15","ResultExaminer":"469","ResultMode":"T","ResultPaperType":"I","ResultPass":"60","ResultQuesRange":"M」」2」10」20」1,4「S」」8」10」80」1,5","ResultQuesRangeI":"4||7」10「4||8」10「5||1」10「5||10」10「5||2」10「5||3」10「5||4」10「5||5」10「5||6」10「5||8」10","ResultResit":"Y","ResultResitNum":"0","ResultScore":"100","ResultTimeList":"","ResultType":"54||1","ReulstOperationRange":"","StartDate":"2024-01-01","Status":"Y","StudentClassDR":"7","StudentTeacherDR":"8","TeacherStudentDR":"9","TimeList":"2024-01-01 00:00」2024-01-10 00:00」2023-12-20 00:00」考核地点1」2「2024-01-11 00:00」2024-01-21 00:00」2024-01-01 00:00」考核地点2」3「2024-01-21 00:00」2024-01-30 00:00」2024-01-15 00:00」考核地点3」4","dirllFileSubDR":"","fileDownFlag":"N","fileName":"","filesOfFile":"","filesUrl":"","finishStand":"1,5,4","passStand":"1,4,5,7,6","videoPass":"","videoQuestion":"","ExamineeListDesc":"护士层级:N1,N2,N3","ExamineeWardDesc":"","orderList":"1,0,0","startStatus":"N","OrderFlag":"N","subID":"13||336","DrillResult":"","DrillStep":"0","OrderFlag":"N","OrderNum":"","Remark":"","ResultOpeUseDate":"","ResultOpeUseOrderTime":"","ResultOpeUseScore":"","ResultOpeUseTime":"","ResultUseDate":"","ResultUseResitNum":"","ResultUseTime":"","ScoreUsedFlag":"","SignEndTime":"","SignStartTime":"","UseClassScore":"","UseDrillScore":"","UseDrillScoreStatus":"","UseHomeworkScore":"","UseHomeworkScoreStatus":"","UseResultScore":"","UserDR":"338","WardDR":"1","classDate":"","classUseResitNum":"","classUseTime":"","videoAnswerNum":"","videoCurrentTime":"","videoDuration":"","videoRightNum":"","ExceptionDR":"","HomeworkUrl":"","perNo":"1009","perName":"闵凤英","wardDesc":"保健科护理单元","SignData":"","UseStatusDesc1":"未完成","videoTimeRate":"0%","UseStatusDesc2":"未完成","UseStatusDesc3":"已通过","UseStatusDesc4":"未完成","DrillUseSurveyStatus":"未提交","UseStatusDesc5":"未完成","UseStatusDesc6":"未完成","UseStatusDesc7":"已完成","DrillResultDesc":"未完成"}
			if (activeType == 'examine') {
				data = {'title':'2021年第一次三基技操考核','orderIndex':0,'info':'<div>院级</div><div>30分钟</div>'}
			}
		}else if (pageName == 'teachList') {
			var textTip = this.querySelector('.imgTitle')
			if (textTip) {
				activeType = 'tongji'
			}else{
				activeType = 'teacher'
			}
		}else if (pageName == 'examList') {
			var textTip = this.querySelector('.textTip').innerText
			if (textTip == '技操考核') {
				activeType = '技操'
			}else{
				activeType = '理论'
			}
		}
		var type = this.getAttribute('data-type')
		if (pageName!="") {
			var extras = {sourceData:data,fromPage:'teach',pageType:activeType}
			
			var webview = plus.webview.create('../TeachPages/'+pageName+'.html', pageName, {
				background: '#fff',
				statusbar: {
					background: '#fff'
				}
			},extras);
			webview.show('fade-in');
		}
	}
	
	function toTrainOrOrder(){
		//console.log('toTrainOrOrder')
		var activeType = getActiveSegmentType();
		if (activeType != 'class') {
			mui.toast('努力开发中...')
			return
		}
		var pageName = this.getAttribute('data-page')
		var index = this.getAttribute('data-index')
		var dict = classArr[index]
		if (index == '1'&&dict['subID']==undefined) {
			dict['subID'] = dict.ExamineeWardDesc.split('subID|')[1]||''
		}
		var webview = plus.webview.create('../TeachPages/'+pageName+'.html', pageName, {
			background: '#fff',
			statusbar: {
				background: '#fff'
			}
		},{sourceData:dict,pageType:activeType});
		webview.show('fade-in');
		webview.addEventListener('close',function(){
			if (activeType == 'class') {
				refreshMainPage(0)
			}else{
				refreshMainPage(1)
			}
		})
	}
	function getTrainData(){
		mui('#trainWrapper').off('tap','.openWindow',toTrainOrOrder);
		$("#latestTrain")[0].innerHTML = ''
		var pdict = {'loginID':loginID,'stDate':today, 'endDate':afterMonthDay}
		var paramDict = {'method':'web.INMTeaComm:FindDrillReleaseSubList','params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict))
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result.msgcode != '1') {
				$("#latestTrain")[0].innerHTML = result.msg
				return
			}
			if (result.data == undefined) {
				$("#latestTrain")[0].innerHTML = 'data字段为空'
				return
			}
			updateLatestTrainUI(result.data)
		}, function(errorStr) {
			$("#latestTrain")[0].innerHTML = errorStr
		});
	}
	function getExamData(){
		return
		mui('#examineWrapper').off('tap','.openWindow',toTrainOrOrder);
		$("#latestExam")[0].innerHTML = ''
		var pdict = {'loginID':loginID,'stDate':today, 'endDate':afterMonthDay}
		var paramDict = {'method':'web.INMTeaComm:FindDrillReleaseSubList','params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict))
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result.msgcode != '1') {
				$("#latestExam")[0].innerHTML = result.msg
				return
			}
			if (result.data == undefined) {
				$("#latestExam")[0].innerHTML = 'data字段为空'
				return
			}
			updateLatestExamUI(result.data)
		}, function(errorStr) {
			$("#latestExam")[0].innerHTML = errorStr
		});
	}
	
	function updateLatestTrainUI(dataArr){
		var currDateTime = getCurrDateTime()
		var endDate = ''
		console.log(JSON.stringify(dataArr))
		for (var i = 0; i < dataArr.length; i++) {
			var dict = dataArr[i]
			var wayDesc = dict['ReleaseWay'] == 'O'?'上':'下'
			if (dict['ReleaseWay'] == 'D' &&dict['OrderFlag'] != 'Y') { //线下 还未预约
				if (classArr[1]) {
					continue
				}
				//预约时间还未截止
				var TimeList = (dict['TimeList']||'').split('「')
				for (var j = 0; j < TimeList.length; j++) {
					var oneTime = (TimeList[j].split('」')[2])||''
					if (oneTime == '') {
						continue
					}
					if (oneTime > currDateTime) {
						classArr[1]=dict
						break;
					}
				}
			}else{
				if (dict['StartDate'] > today) {
					continue //还未开始
				}
				if (endDate == '') {
					endDate = dict['EndDate']
					classArr[0]=dict
					continue
				}
				if (endDate > dict['EndDate']) {
					endDate = dict['EndDate']
					classArr[0]=dict
				}
			}
		}
		var html = ''
		if (classArr[0]) {
			var dict = classArr[0]
			html += '<div class="cardLine openWindow" data-page="toTrain" data-index="0">'+
				'<div class="classTitle">'+dict['ReleaseDesc']+'</div>'+
				'<div class="classSubInfo">培训日期: '+dict['StartDate']+' - '+dict['EndDate']+'</div>'+
				'<div class="mui-btn mui-btn-primary baseBtn portraitCenter">去培训</div></div>'
		}
		if (classArr[1]) {
			var dict = classArr[1]
			//console.log(JSON.stringify(dict))
			var CoursesType = dict['CoursesType'] == 'Y'?'预约':'报名'
			var TimeList = (dict['TimeList']||'').split('「')
			html += '<div class="cardLine openWindow" data-page="toOrder" data-index="1">'+
				'<div class="classTitle">'+dict['ReleaseDesc']+'<div>'+TimeList.length+'批次</div></div>'+
				'<div class="classSubInfo">培训日期: '+dict['StartDate']+' - '+dict['EndDate']+'</div>'+
				'<div class="mui-btn mui-btn-primary baseBtn portraitCenter">去'+CoursesType+'</div></div>'
		}
		if (html == '') {
			html = '一个月内暂无未完成的课程'
		}
		$("#latestTrain")[0].innerHTML = html
		mui('#trainWrapper').on('tap','.openWindow',toTrainOrOrder);
	}
	function updateLatestExamUI(dataArr){
		//classArr[2] 去考核  classArr[3]去预约考核
		var html = ''
		if (classArr[2]) {
			var dict = classArr[2]
			html += '<div class="cardLine openWindow" data-page="toExamine">'+
				'<div class="classTitle">'+dict['ReleaseDesc']+'</div>'+
				'<div class="classSubInfo">培训日期: '+dict['StartDate']+' - '+dict['EndDate']+'</div>'+
				'<div class="mui-btn mui-btn-primary baseBtn portraitCenter" data-index="2">去培训</div></div>'
		}
		if (classArr[3]) {
			var dict = classArr[3]
			var CoursesType = dict['CoursesType'] == 'Y'?'预约':'报名'
			var TimeList = (dict['TimeList']||'').split('「')
			html += '<div class="cardLine openWindow" data-page="toOrder">'+
				'<div class="classTitle">'+dict['ReleaseDesc']+'<div>'+TimeList.length+'批次</div></div>'+
				'<div class="classSubInfo">培训日期: '+dict['StartDate']+' - '+dict['EndDate']+'</div>'+
				'<div class="mui-btn mui-btn-primary baseBtn portraitCenter" data-index="3">去'+CoursesType+'</div></div>'
		}
		$("#latestExam")[0].innerHTML = html
		mui('#examineWrapper').on('tap','.openWindow',toTrainOrOrder);
	}
	function getCurrDateTime(){
		var dateObj = new Date()
		var currMon = dateObj.getMonth() + 1
		var currDay = dateObj.getDate()
		var currDate = dateObj.getFullYear() +'-'+(currMon<10?('0'+currMon):currMon)+'-'+(currDay<10?('0'+currDay):currDay)
		var hourInt = dateObj.getHours()
		var minuteInt = dateObj.getMinutes()
		var currTime = (hourInt<10?('0'+hourInt):hourInt)+':'+(minuteInt<10?('0'+minuteInt):minuteInt)
		return currDate+' '+currTime
	}
	function getDayAfterMonth(dayStr,count){
		var ymDict = getYMDWithStr(dayStr)
		var year = ymDict.year
		var month = ymDict.month + count
		if (month > 12) {
			var yu = month - 12
			var month = yu % 12
			year += Math.floor(yu / 12)
		}
		var day = ymDict.day
		if (day > 28) {
			var maxDay = getMonthMaxDay(year,month,day);
			if (day > maxDay) {
				day = maxDay
			}
		}
		var thisDay = year + "-"
		if (month < 10) {
			thisDay +='0'
		}
		thisDay+= month + "-" 
		if (day < 10) {
			thisDay +='0'
		}
		thisDay += day;
		return thisDay;
	}
})(mui);
/*
线上课程     线下课程
培训课件     培训考勤

培训中的随堂练习
没有问答题,直接出结果

培训中的结课考核
1.理论考核--结果在考核模块-->考官-->在线阅卷
2.技操考核--结果在考核模块-->考官-->技操打分

培训中的课后作业
讲师或考官在PC端预览/下载打分;APP端不涉及打分

考官的在线阅卷
只有过了培训/考核截止时间考官才可以阅卷---防止泄题

随堂练习和结课考核
考试和重考时都是随机抽题的,这次考试和重考的题目都是随机的---因为有错题分析.

*/